<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends BaseController {
    

public function userlist(){
		$usersmodel=M('users');
		$users=$usersmodel->order('id asc')->select();
		//dump($users);
		$this->users=$users;
		$this->display();
	}
		public function deluser($id){
 	
        $usersmodel=M('users');
        $res=$usersmodel->where("id=$id")->find();
        $photoPath = realpath("./Public/Uploads/photo/".$res['photo']);
        unlink($photoPath);
        //$res=$usersmodel->where("id=$id")->delete();
        if ($usersmodel->delete($id)) {
            $this->success('删除成功！');
        } else {
            $this->error('删除失败');
        }



        }
      

	

    public function edituser(){
    //密码重置
 	 //dump($_GET);
     $id=$_GET['id'];
 	 echo $id;
 	 $data['password']='123456';
 	 $usersModel=M('users');
 	 if (false!==$usersModel->where("id=$id")->save($data)) {
           echo $usersModel->getLastSql();//显示之前要修改的内容
            $this->success('密码重置成功！');
        } else {
            $this->error('密码重置失败');//2个等于号（==）代表两边类型一样，数值一样
        }
	

     }
     public function state(){
 	 //dump($_GET);
     $id=$_GET['id'];
 	 echo $id;//如果只写上面这3行，注释部分，会再页面显示要删除的数据
 	 $state['state']='1';
 	 $usersModel=M('users');
 	 if (false!==$usersModel->where("id=$id")->save($state)) {
           echo $usersModel->getLastSql();//显示之前要修改的内容
            $this->success('暂停使用成功！');
        } else {
            $this->error('暂停使用失败');//2个等于号（==）代表两边类型一样，数值一样
        }
	

     }
     public function isstate(){
 	 //dump($_GET);
     $id=$_GET['id'];
 	 echo $id;//如果只写上面这3行，注释部分，会再页面显示要删除的数据
 	 $isstate['state']='0';
 	 $usersModel=M('users');
 	 if (false!==$usersModel->where("id=$id")->save($isstate)) {
           echo $usersModel->getLastSql();//显示之前要修改的内容
            $this->success('取消禁用成功！');
        } else {
            $this->error('取消禁用失败');//2个等于号（==）代表两边类型一样，数值一样
        }
	

     }

function edit($id){//修改用户信息
        $user = M('users');
        //$data['telephone']=$_SESSION['telephone'];
        $res = $user->where("id = $id")->find($data);
        $this->list=$res;
        $this->display();
    }
    function doUpdate($id){
       // $telephone = $_SESSION['telephone'];
        $usersmodel=M('users');
        if($_FILES['photo']['error'] == 0){
            $logoinfo = $this->upload();
            $pname = $logoinfo['file']['savename'];
        } else {
            $pname = "default.jpg";
        }
        
        $data['aliasname']=I('post.aliasname');
       $data['telephone']=I('post.telephone');
        $data['email']=I('post.email');
        $data['photo'] = $pname;
        $res=$usersmodel->where("id = $id")->save($data);
        if (false!==$res){
            $this->success('信息修改成功','userlsit');
        } else{
            $this->error('信息修改失败');
        }
    }

public function upload(){
                //上传头像
              $upload = new \Think\Upload();// 实例化上传类
              $upload->maxSize  = 3145728 ;// 设置附件上传大小
              //$upload->allowExts  = array('mp4','jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
              $upload->exts  = array('jpg', 'gif', 'png', 'jpeg');
              $upload->rootPath  =  './';
              $upload->savePath =  'Public/Uploads/photo/';// 设置附件上传目录

              $upload->autoSub = false;
              $upload->saveName = date("YmdHis").rand(100,999);//定义名字
               // 上传单个文件 
              $info = $upload->upload();                    
                  if(!$info) {// 上传错误提示错误信息
                      $this->error($upload->getError());
                    }else{// 上传成功 获取上传文件信息
                return $info;
                         }
    } 





}

